From: Jeroen van der Heijden Date: Mon, 27 Aug 2018 11:34:39 +0000 (+0200) Subject: PEP8 Python test files X-Git-Tag: archive/raspbian/2.0.44-1+rpi1~1^2~3^2~8^2~84 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/success//%22http:/www.example.com/cgi/success/?a=commitdiff_plain;h=f92ad07d90bdce5af4374056ad433bb0ee2c6e20;p=siridb-server.git PEP8 Python test files --- diff --git a/test/data_google_finance.py b/test/data_google_finance.py index b48ad910..2427dedc 100755 --- a/test/data_google_finance.py +++ b/test/data_google_finance.py @@ -7,6 +7,7 @@ URL = \ 'http://www.google.com/finance/getprices?' \ 'i={interval}&p={days}d&f=d,o,h,l,c,v&df=cpct&q={ticker}' + def _data_to_csv(data, ticker, interval): lines = [] series = None @@ -55,6 +56,7 @@ async def get_google_finance_data(ticker, interval, days): content = await resp.text() return _data_to_csv(content, ticker, interval) + async def save_google_finance_data(fn, ticker, interval, days): """Returns Google Finance Data in CSV format. @@ -68,6 +70,7 @@ async def save_google_finance_data(fn, ticker, interval, days): with open(fn, 'w') as f: f.write(csv_data) + async def print_google_finance_data(ticker, interval, days): """Prints Google Finance Data in CSV format. @@ -76,7 +79,7 @@ async def print_google_finance_data(ticker, interval, days): :param days: The historical data period in days :return: None """ - print (await get_google_finance_data(ticker, interval, days)) + print(await get_google_finance_data(ticker, interval, days)) if __name__ == '__main__': parser = argparse.ArgumentParser() @@ -107,4 +110,3 @@ if __name__ == '__main__': ticker=args.ticker, interval=args.interval, days=args.days)) - diff --git a/test/siridb-random-data.py b/test/siridb-random-data.py index 1e575ab8..53e29e3a 100755 --- a/test/siridb-random-data.py +++ b/test/siridb-random-data.py @@ -466,7 +466,7 @@ Home-page: https://github.com/transceptor-technology/siridb-email-check if datetime.datetime.strptime( args.start_date, '%Y-%m-%d') >= datetime.datetime.today(): exit('start date must be a date before today.') - except: + except Exception: exit('invalid date: {}'.format(args.start_date)) setup_logger(args) diff --git a/test/test_cluster.py b/test/test_cluster.py index be46fec0..aab5369d 100644 --- a/test/test_cluster.py +++ b/test/test_cluster.py @@ -63,6 +63,7 @@ class TestCluster(TestBase): return False + if __name__ == '__main__': SiriDB.LOG_LEVEL = 'INFO' Server.HOLD_TERM = True diff --git a/test/test_group.py b/test/test_group.py index f0e3b930..4a536870 100644 --- a/test/test_group.py +++ b/test/test_group.py @@ -111,23 +111,28 @@ class TestGroup(TestBase): await self.client1.query('alter group `two` set expression /.2/'), {'success_msg': "Successfully updated group 'two'."}) - time.sleep(3) result = await self.client0.query('list series `a` & `two`') self.assertEqual(sorted(result.pop('series')), [['a2']]) result = await self.client0.query('list series `a` | `two`') - self.assertEqual(sorted(result.pop('series')), [['a1'], ['a2'], ['b2'], ['c2']]) + self.assertEqual( + sorted(result.pop('series')), + [['a1'], ['a2'], ['b2'], ['c2']]) result = await self.client0.query('list series `a` ^ `two`') - self.assertEqual(sorted(result.pop('series')), [['a1'], ['b2'], ['c2']]) + self.assertEqual( + sorted(result.pop('series')), + [['a1'], ['b2'], ['c2']]) result = await self.client0.query('list series `a` - `two`') self.assertEqual(sorted(result.pop('series')), [['a1']]) result = await self.client0.query('list series `a`, `two` - "c2"') - self.assertEqual(sorted(result.pop('series')), [['a1'], ['a2'], ['b2']]) + self.assertEqual( + sorted(result.pop('series')), + [['a1'], ['a2'], ['b2']]) result = await self.client0.query('list series `a`, `two` & "c2"') self.assertEqual(sorted(result.pop('series')), [['c2']]) @@ -169,6 +174,7 @@ class TestGroup(TestBase): return False + if __name__ == '__main__': SiriDB.LOG_LEVEL = 'CRITICAL' Server.HOLD_TERM = True diff --git a/test/test_list.py b/test/test_list.py index 5472fe38..154c0fa8 100644 --- a/test/test_list.py +++ b/test/test_list.py @@ -24,8 +24,8 @@ TIME_PRECISION = 's' class TestList(TestBase): title = 'Test list' - GEN_POINTS = functools.partial(gen_points, n=1, time_precision=TIME_PRECISION) - + GEN_POINTS = functools.partial( + gen_points, n=1, time_precision=TIME_PRECISION) @default_test_setup(1, time_precision=TIME_PRECISION) async def run(self): @@ -96,7 +96,8 @@ class TestList(TestBase): await self.client0.query('alter database set list_limit 5000') with self.assertRaisesRegexp( QueryError, - 'Limit must be a value between 0 and 5000 but received: 6000.*'): + 'Limit must be a value between 0 and 5000 ' + 'but received: 6000.*'): await self.client0.query( 'list series limit 6000') diff --git a/test/test_pipe_support.py b/test/test_pipe_support.py index bde86f63..68038296 100644 --- a/test/test_pipe_support.py +++ b/test/test_pipe_support.py @@ -41,10 +41,10 @@ DATA = { if os.path.exists(PIPE_NAME): os.unlink(PIPE_NAME) + class TestPipeSupport(TestBase): title = 'Test pipe support object' - @default_test_setup(1, pipe_name=PIPE_NAME) async def run(self): diff --git a/test/test_pool.py b/test/test_pool.py index 420cc738..d42078c0 100644 --- a/test/test_pool.py +++ b/test/test_pool.py @@ -27,7 +27,6 @@ class TestPool(TestBase): await client.insert_some_series(series, n=0.01, timeout=timeout) await asyncio.sleep(1.0) - @default_test_setup(4) async def run(self): diff --git a/test/test_select.py b/test/test_select.py index 6ae91bd1..4031e4e0 100644 --- a/test/test_select.py +++ b/test/test_select.py @@ -218,7 +218,7 @@ class TestSelect(TestBase): self.assertEqual( await self.client0.query( 'select filter(/l.*/) from * where type == string'), - {'log': [p for p in DATA['log'] if re.match('l.*', p[1])]}) + {'log': [p for p in DATA['log'] if re.match('l.*', p[1])]}) self.assertEqual( await self.client0.query( diff --git a/test/test_series.py b/test/test_series.py index 14dd090e..37b35945 100644 --- a/test/test_series.py +++ b/test/test_series.py @@ -20,7 +20,9 @@ from testing import UserAuthError PI = 'ԉ' -Klingon = '     qajunpaQHeylIjmo’ batlh DuSuvqang charghwI’ ‘It.' +Klingon = '     ' + \ + 'qajunpaQHeylIjmo’ batlh DuSuvqang charghwI’ ‘It.' + class TestSeries(TestBase): title = 'Test series object' diff --git a/test/test_syslog.py b/test/test_syslog.py index 5c841676..16f99075 100644 --- a/test/test_syslog.py +++ b/test/test_syslog.py @@ -42,7 +42,6 @@ MTCH = re.compile( class TestSyslog(TestBase): title = 'Test with syslog data' - async def insert_syslog(self, batch_size=100): with open(SYSLOG, 'r') as f: @@ -85,6 +84,7 @@ class TestSyslog(TestBase): return False + if __name__ == '__main__': SiriDB.LOG_LEVEL = 'CRITICAL' Server.HOLD_TERM = True diff --git a/test/test_user.py b/test/test_user.py index 97802afb..bc39d0a1 100644 --- a/test/test_user.py +++ b/test/test_user.py @@ -47,14 +47,19 @@ class TestUser(TestBase): 'Password should be at least 4 characters.'): await self.client0.query('create user "aa" set password "123" ') - result = await self.client0.query('create user "sasientje" set password "blabla" ') - self.assertEqual(result.pop('success_msg'), "Successfully created user 'sasientje'.") + result = await self.client0.query( + 'create user "sasientje" set password "blabla" ') + self.assertEqual( + result.pop('success_msg'), + "Successfully created user 'sasientje'.") result = await self.client0.query('list users where access < modify ') self.assertEqual(result.pop('users'), [['sasientje', 'no access']]) result = await self.client0.query('grant modify to user "sasientje" ') - self.assertEqual(result.pop('success_msg'), "Successfully granted permissions to user 'sasientje'.") + self.assertEqual( + result.pop('success_msg'), + "Successfully granted permissions to user 'sasientje'.") await self.db.add_replica(self.server1, 0) await self.assertIsRunning(self.db, self.client0, timeout=10) @@ -66,14 +71,22 @@ class TestUser(TestBase): result = await self.client1.query('list users where access < full ') self.assertEqual(result.pop('users'), [['sasientje', 'modify']]) - result = await self.client1.query('revoke write from user "sasientje" ') - self.assertEqual(result.pop('success_msg'), "Successfully revoked permissions from user 'sasientje'.") + result = await self.client1.query( + 'revoke write from user "sasientje" ') + self.assertEqual( + result.pop('success_msg'), + "Successfully revoked permissions from user 'sasientje'.") - result = await self.client1.query('grant show, count to user "sasientje"') - result = await self.client1.query('list users where access < modify ') - self.assertEqual(result.pop('users'), [['sasientje', 'alter, count, drop and show']]) + result = await self.client1.query( + 'grant show, count to user "sasientje"') + result = await self.client1.query( + 'list users where access < modify ') + self.assertEqual( + result.pop('users'), + [['sasientje', 'alter, count, drop and show']]) - result = await self.client1.query('create user "pee" set password "hihihaha" ') + result = await self.client1.query( + 'create user "pee" set password "hihihaha" ') time.sleep(0.1) result = await self.client0.query('list users where name ~ "p"') self.assertEqual(result.pop('users'), [['pee', 'no access']]) @@ -85,9 +98,11 @@ class TestUser(TestBase): with self.assertRaisesRegexp( QueryError, "Password should be at least 4 characters."): - result = await self.client1.query('alter user "sasientje" set password "dag" ') + result = await self.client1.query( + 'alter user "sasientje" set password "dag" ') - result = await self.client1.query('alter user "sasientje" set password "dagdag"') + result = await self.client1.query( + 'alter user "sasientje" set password "dagdag"') await self.server0.start(sleep=35) @@ -107,12 +122,15 @@ class TestUser(TestBase): result = await self.client0.insert({'no access test': [[1, 1.0]]}) result = await self.client1.query('drop user "sasientje" ') - self.assertEqual(result.pop('success_msg'), "Successfully dropped user 'sasientje'.") + self.assertEqual( + result.pop('success_msg'), + "Successfully dropped user 'sasientje'.") time.sleep(0.1) for client in (self.client0, self.client1, self.client2): result = await client.query('count users') - self.assertEqual(result.pop('users'), 2, msg='Expecting 2 users (iris and pee)') + self.assertEqual( + result.pop('users'), 2, msg='Expecting 2 users (iris and pee)') result = await self.client0.query('count users where name == "pee"') self.assertEqual(result.pop('users'), 1, msg='Expecting 1 user (pee)') @@ -130,22 +148,26 @@ class TestUser(TestBase): with self.assertRaisesRegexp( QueryError, "^User name contains illegal characters.*"): - result = await self.client1.query('alter user "pee" set name " p " ') + result = await self.client1.query( + 'alter user "pee" set name " p " ') with self.assertRaisesRegexp( QueryError, "User 'iris' already exists."): - result = await self.client1.query('alter user "pee" set name "iris" ') + result = await self.client1.query( + 'alter user "pee" set name "iris" ') with self.assertRaisesRegexp( QueryError, "User 'iris' already exists."): - result = await self.client1.query('alter user "pee" set name "iris" ') + result = await self.client1.query( + 'alter user "pee" set name "iris" ') with self.assertRaisesRegexp( QueryError, "Cannot find user: 'Pee'"): - result = await self.client1.query('alter user "Pee" set name "PPP" ') + result = await self.client1.query( + 'alter user "Pee" set name "PPP" ') result = await self.client1.query('alter user "pee" set name "Pee"') self.assertEqual( diff --git a/test/testing/__init__.py b/test/testing/__init__.py index 54a54e73..fe23f73f 100644 --- a/test/testing/__init__.py +++ b/test/testing/__init__.py @@ -43,4 +43,4 @@ def run_test(test, loglevel='CRITICAL'): assert isinstance(test, TestBase) loop = asyncio.get_event_loop() cleanup() - loop.run_until_complete(_run_test(test, loglevel)) \ No newline at end of file + loop.run_until_complete(_run_test(test, loglevel)) diff --git a/test/testing/client.py b/test/testing/client.py index b5d8f375..686d8650 100644 --- a/test/testing/client.py +++ b/test/testing/client.py @@ -73,4 +73,3 @@ class Client: for s in series[:n]: s.commit_points() - diff --git a/test/testing/constants.py b/test/testing/constants.py index 8ec4aca1..14223bcc 100644 --- a/test/testing/constants.py +++ b/test/testing/constants.py @@ -2,6 +2,11 @@ BUILDTYPE = 'Debug' TEST_DIR = './testdir' SIRIDBC = '../{BUILDTYPE}/siridb-server' ADMIN = '/usr/local/bin/siridb-admin' -# VALGRIND = 'valgrind --tool=memcheck --leak-check=full --show-leak-kinds=all --track-origins=yes -v ' +VALGRIND = 'valgrind' + \ + ' --tool=memcheck' + \ + ' --leak-check=full' + \ + ' --show-leak-kinds=all' + \ + ' --track-origins=yes' + \ + ' -v ' VALGRIND = 'valgrind --tool=memcheck ' MAX_OPEN_FILES = 512 # Default value is 32768 but with valgrind 512 is max diff --git a/test/testing/pipe_client.py b/test/testing/pipe_client.py index 9b90eafd..4164e7fe 100644 --- a/test/testing/pipe_client.py +++ b/test/testing/pipe_client.py @@ -25,5 +25,3 @@ class PipeClient(SiriDBAsyncConnection): raise exc else: self._protocol.on_authenticated() - - diff --git a/test/testing/series.py b/test/testing/series.py index dd71d814..bbf3c9a0 100644 --- a/test/testing/series.py +++ b/test/testing/series.py @@ -14,4 +14,3 @@ class Series: for point in self._points: self.points.append(point) self._points = None - diff --git a/test/testing/siridb.py b/test/testing/siridb.py index 51445f37..077c3a5f 100644 --- a/test/testing/siridb.py +++ b/test/testing/siridb.py @@ -131,5 +131,3 @@ class SiriDB: if sleep: await asyncio.sleep(sleep) - -